<template>
    <div class="background">
      <a-card style="margin-bottom: 10px">
        <a-form
          :form="form"
          layout="inline"
          @submit="handleSubmit"
        >
        <a-form-item label="上货季">
                <a-select
                  style="width: 200px"
                  placeholder="请选择上货季"
                  v-model="formContent.scseason"
                  @focus="getDictChildList('SEASON', 'seasonList')"
                  allow-clear
                >
                  <a-select-option
                    :value="item.code"
                    v-for="(item, index) in seasonList"
                    :key="index"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="产品大类">
                <a-select
                  style="width: 200px"
                  placeholder="请选择产品大类"
                  v-model="formContent.scdl"
                  @focus="getDictChildList('PRODUCT_BIGTYPE', 'scdlList')"
                  allow-clear
                >
                  <a-select-option
                    :value="item.code"
                    v-for="(item, index) in scdlList"
                    :key="index"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
              <a-form-item label="产品编号">
                <a-input
                style="width:200px"
                  allow-clear
                  placeholder="请输入产品编号"
                  v-model="formContent.sccode"
                ></a-input>
              </a-form-item>
              <a-form-item label="产品名称">
                <a-input
                style="width:200px"
                  allow-clear
                  placeholder="请输入产品名称"
                  v-model="formContent.scname"
                ></a-input>
              </a-form-item>
              <a-form-item>
                <a-button
                  type="primary"
                  html-type="submit"
                >搜索</a-button>
                <!-- <a-button
                  type="primary"
                  style="margin-left: 10px"
                  @click="add"
                >新建</a-button> -->
              </a-form-item>
        </a-form>
  
      </a-card>
      <a-card>
        <a-table
          bordered
          :loading="loading"
          :scroll="{x: 1500}"
          :pagination="pagination"
          :columns="columns"
          :data-source="dataSource"
          @change="handleTableChange"
        >
          <template
            slot="status"
            slot-scope="txt, record"
          >
            <span v-for="item,i in statusList" :key="i"> 
            <span v-if="item.value == record.status">
              {{ item.name }}
            </span></span>
          </template>
          <template
            slot="ordertype"
            slot-scope="txt, record"
          >
            <span v-if="record.ordertype == 1">调样</span>
            <span v-if="record.ordertype == 2">扩色</span>
            <span v-if="record.ordertype == 3">开发部调样</span>
            <span v-if="record.ordertype == 4">生产部调样</span>
            <span v-if="record.ordertype == 5">套色</span>
          </template>
          <template
            slot="flag"
            slot-scope="txt, record"
          >
            <span v-if="record.flag == 'Y'">已审核</span>
            <span v-if="record.flag == 'N'">草稿</span>
          </template>
          <template
            slot="action"
            slot-scope="txt, record"
          >
            <!-- <a
              class="mr-10"
              @click="add(record)"
            >
              编辑
            </a> -->
            <a
              class="mr-10"
              @click="add(record)"
            >
              审核
            </a> 
           
            <a-popconfirm
              :title="`确定要驳回该项吗?`"
              @confirm="submit(record)"
            >
            <a
              class="mr-10"
            >
              驳回
            </a>
            </a-popconfirm>
          </template>
        </a-table>
      </a-card>
  
      <create
        v-if="showAdd"
        :accRetrievalSampleDetailId="accRetrievalSampleDetailId"
        @close="close"
      ></create>
    </div>
  
  </template>
    
    <script>
  import { retrievalsample, getDictChildList, orderReject, operation,getOrderList } from '@api/material/index'
  import { postAction } from '@/api/manage'
  
  const columns = [

    {
      title: '单据编号',
      width: 150,
      dataIndex: 'billno',
      fixed: 'left'
    },
    {
      title: '上货季',
      width: 100,
      dataIndex: 'scseasonValue'
    },
    {
      title: '订单类型',
      width: 100,
      dataIndex: 'ordertype',
      scopedSlots: { customRender: 'ordertype' }
    },
    {
      title: '产品编号',
      width: 130,
      dataIndex: 'sccode',
      scopedSlots: { customRender: 'sccode' }
    },
    {
      title: '产品名称',
      width: 250,
      dataIndex: 'scname',
    },
    {
      title: '产品成分',
      width: 240,
      dataIndex: 'sccf',
    },
    
    {
      title: '有效门幅',
      width: 180,
      dataIndex: 'scmf',
    },
    {
      title: '面料克重',
      width: 100,
      dataIndex: 'scmlkz',
    },
    {
      title: '调样价格',
      width: 110,
      dataIndex: 'scprice',
    },
    {
      title: '申请总数量',
      width: 120,
      dataIndex: 'ordersl',
    },
    {
      title: '实际总数量',
      width: 120,
      dataIndex: 'n3',
    },
    {
      title: '总计费用',
      width: 110,
      dataIndex: 'n2',
    },
    {
      title: '供应商',
      width: 200,
      dataIndex: 'scsupvalue'
    },
    {
      title: '采购员',
      width: 140,
      dataIndex: 'scorder'
    },
    {
      title: '下单日期',
      width: 220,
      dataIndex: 'date1'
    },
    {
      title: '状态',
      width: 70,
      dataIndex: 'flag',
      scopedSlots: { customRender: 'flag' }
    },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      scopedSlots: { customRender: 'action' }
    }
  ]
  export default {
    components: {
    },
    data() {
      return {
        urlKey: 'basemgt-material/',
        columns,
        // statusList:[{value:10,name:'草稿'},{value:20,name:'待开发审核'},{value:30,name:'待业务审核'},{value:40,name:'业务已审核'},{value:50,name:'退回草稿'},{value:60,name:'无效'}],
        statusList:[{value:10,name:'草稿'},{value:50,name:'退回草稿'},{value:70,name:'强制作废'}],
        form: this.$form.createForm(this),
        showAdd: false,
        loading: false,
        dataSource: [],
        seasonList:[],
        scdlList:[],
        pagination: {
          total: 0,
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30', '40'],
          showQuickJumper: true,
          showSizeChanger: true,
          showTotal: total => `共 ${total} 条记录`,
          itemRender: (current, type, originalElement) => {
            if (type === 'prev') {
              return <a>上一页</a>
            } else if (type === 'next') {
              return <a>下一页</a>
            }
            return originalElement
          }
        },
        formContent: {
          scseason:undefined,
          scdl:undefined,
          scname:'',
          sccode:'',
          djlb:2,
        },
      }
    },
    computed: {
      jobNumber() {
        return this.$store.getters.userInfo.workNo || ''
      }
    },
    mounted() {
      this.loadData()
    },
  
    methods: {
      close() {
        this.showAdd = false
        this.loadData()
      },
      add(record) {
        if (record) {
          this.$router.push({ path: '/material-file/sampleComfirm/add', query: { billno: record.billno } })
        } else {
          this.$router.push({ path: '/material-file/sampleComfirm/add' })
        }
      },
      handleTableChange(pagination) {
        this.pagination = pagination
        this.loadData()
      },
      handleSubmit(e) {
        e.preventDefault()
        this.getList(1)
      },
      loadData() {
        this.getList()
      },
      async getDictChildList(name, list) {
        const params = {
          name: name
        }
        try {
          const res = await getDictChildList(params)
          if (res.code == 200) {
            this[list] = res.data
          } else {
            if (res.msg) {
              this.$message.error(res.msg)
            } else {
              this.$message.error('获取数据字典失败！')
            }
          }
        } catch (error) {
          this.$message.error('获取数据字典失败！')
        }
      },

      async getList(key) {
        this.loading = true
        const params = this.formContent
        params.current = this.pagination.current
        params.size = this.pagination.pageSize
        params.billtype = 30
        if (key) {
          params.current = 1
        }
        try {
          const res = await getOrderList(params)
          if (res.code == 200) {
            this.dataSource = res.data.records
            this.pagination.total = res.data.total
          } else {
            this.$message.warning(res.msg)
          }
        } catch (error) {
          this.$message.warning('获取列表失败！')
        } finally {
          this.loading = false
        }
      },
      async submit(record) {
      const res = await orderReject({ billno: record.billno, jobNumber: this.jobNumber, sccode: record.sccode,})
      if (res.code == 200) {
        this.$message.success('驳回成功！')
        this.loadData()
      } else {
        this.$message.warning(res.msg)
      }
    },
      async doOperation(record, operate) {
        let params = {
          accId: record.accId,
          jobNumber: this.jobNumber,
          operate: operate
        }
        const res = await operation(params)
        if (res.code == 200) {
          this.$message.success('状态更新成功！')
          this.loadData()
        } else {
          this.$message.warning(res.msg)
        }
      }
    }
  }
  </script>
    <style lang="less" scoped>
  .background {
    background: transparent;
  }
  
  .mr-10 {
    margin-left: 10px;
  }
  </style>